package com.birdpiss.commons.manager;

import java.util.List;

import javax.annotation.PostConstruct;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.birdpiss.commons.dao.interfaces.UserDao;
import com.birdpiss.commons.domain.User;
import com.birdpiss.commons.manager.interfaces.UserManager;

/**
 * The Class DefaultUserManager.
 *
 * @author mark
 */
@Service("userManager")
public class DefaultUserManager implements UserManager {

	private static final Logger log = Logger.getLogger(UserManager.class);
	private UserDao userDao;

	/**
	 * Verify DI was setup correctly and perform any post DI initialization.
	 */
	@PostConstruct
	public void initialize() {
		if (this.userDao == null) throw new BeanCreationException("Must set User Dao");
	}

	/* (non-Javadoc)
	 * @see com.birdpiss.commons.manager.interfaces.UserManager#getAllUsers()
	 */
	@Override
	public List<User> getAllUsers() {
		if (log.isDebugEnabled()) log.debug("Getting all the users...");
		return this.userDao.getAllUsers();
	}

	/* (non-Javadoc)
	 * @see com.birdpiss.commons.manager.interfaces.UserManager#getUser(java.lang.Integer)
	 */
	@Override
	public User getUser(Integer userId) {
		if (log.isDebugEnabled()) log.debug("Getting user id: " + userId);
		return this.userDao.getUser(userId);
	}

	/**
	 * Sets the user dao.
	 *
	 * @param userDao the new user dao
	 */
	@Autowired
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

}
